home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Firebug 1.3.3 / firebug-1.3.3-fx.xpi / content / firebug / commandLineInjected.js < prev    next >
Encoding:
JavaScript  |  2009-02-19  |  2.6 KB  |  80 lines

  1. /* See license.txt for terms of usage */
  2.  
  3. var _FirebugCommandLine = 
  4. {
  5.     init: function()
  6.     {
  7.         // Define console functions.
  8.         var commands = ["$", "$$", "$x", "$n", "cd", "clear", "inspect", "keys", 
  9.             "values", "debug", "undebug", "monitor", "unmonitor", 
  10.             "monitorEvents", "unmonitorEvents", "profile", "profileEnd", "copy"];
  11.         for (var i=0; i<commands.length; i++)
  12.         {
  13.             var command = commands[i];
  14.  
  15.             // If the method is already defined, don't override it. 
  16.             if (window[command])
  17.                 continue;
  18.  
  19.             this[command] = new Function(
  20.                 "return window.console.notifyFirebug(arguments, '" + command + "', 'firebugExecuteCommand');");
  21.         }
  22.         
  23.         // Define console shortcuts
  24.         var consoleShortcuts = ["dir", "dirxml"];
  25.         for (var i=0; i<consoleShortcuts.length; i++)
  26.         {
  27.             var command = consoleShortcuts[i];
  28.             this[command] = new Function("return window.console." + command + ".apply(window.console, arguments)");
  29.         }
  30.  
  31.         // Define console variables.
  32.         var props = ["$0", "$1"];
  33.         for (var j=0; j<props.length; j++)
  34.         {
  35.             var prop = props[j];
  36.             if (top[prop])
  37.                 continue;
  38.  
  39.             this.__defineGetter__(prop, new Function(
  40.                 "return window.console.notifyFirebug(arguments, '" + prop + "', 'firebugExecuteCommand');"));
  41.         }
  42.         
  43.         this.attachCommandLine();
  44.     },
  45.     
  46.     attachCommandLine: function()
  47.     {
  48.         var element = window.console.getFirebugElement();
  49.         var self = this;
  50.         element.addEventListener("firebugCommandLine", function _firebugEvalEvent(event)
  51.         {
  52.             //window.dump("_firebugEvalEvent firebugCommandLine\n");
  53.             var element = event.target;
  54.             var expr = element.getAttribute("expr"); // see commandLine.js
  55.             self.evaluate(expr);
  56.             //window.dump("_firebugEvalEvent did evaluate on "+expr+"\n");
  57.         }, true);
  58.         element.setAttribute("firebugCommandLineAttached", "true")
  59.         //window.dump("Added listener for firebugCommandLine event");
  60.     },
  61.  
  62.     evaluate: function(expr)
  63.     {
  64.         try
  65.         {
  66.             var result = window.eval(expr);
  67.             if (typeof result != "undefined")
  68.                 window.console.notifyFirebug([result], "evaluated", "firebugAppendConsole");
  69.         }
  70.         catch(exc)
  71.         {
  72.             var result = exc;
  73.             result.source = expr;
  74.             window.console.notifyFirebug([result], "evaluateError", "firebugAppendConsole");
  75.         }
  76.     },
  77. };
  78.  
  79. _FirebugCommandLine.init();
  80.